package com.lagou.task.test04;

import java.util.LinkedList;
import java.util.List;

public class StudentManagement {

    private List<Student> list = new LinkedList<>();

    public void add(Student student) {
        list.add(student);
    }

    public boolean del(int id) {
        Student student = find(id);
        if (null == student) {
            return false;
        }
        return list.remove(student);
    }

    public Student find(int id) {
        Student student = null;
        for (Student obj:list) {
            if (obj.getId() == id) {
                student = obj;
            }
        }
        return student;
    }

    public List<Student> findByName(String name) {
        List<Student> students = new LinkedList<>();
        int i = 0;
        for (Student obj:list) {
            if (name.equals(obj.getName())) {
                students.add(obj);
            }
        }
        return students;
    }

    public List<Student> findByAge(int age) {

        List<Student> students = new LinkedList<>();
        int i = 0;
        for (Student obj:list) {
            if (age == obj.getAge()) {
                students.add(obj);
            }
        }
        return students;
    }

    public void show() {
        System.out.println(list);
    }
}
